@extends("backend.master")

@section("content")
	<h2>{{$title}}</h2>

	<div class="search">
		{{Form::open(array("method"=>"get","class"=>"form-inline"))}}
			<div class="form-group">
				<label class="sr-only" for="exampleInputEmail2">Email address</label>
				{{Form::text("search",Input::get("search"),array("class"=>"form-control","id"=>"exampleInputEmail2","placeholder"=>"Tìm kiếm..."))}}
			</div>
			{{Form::submit("Search",array("class"=>"btn btn-default"))}}
		{{Form::close()}}
	</div>

	@if(count($posts) > 0)	
		<table class="table table-bordered table-striped table-hover">

				<tr>
					<a href="{{URL::route('createPost_get')}}" class="btn btn-primary" >Thêm bài viết</a>
				</tr>

				@if ($search != "")
					<h3>Tìm thấy: <span style="color:red">{{count($posts)}}</span> bài viết</h3>
				@endif

				<tr class="info">
					<td>Title</td>
					<td>Description</td>
					<td>Content</td>
					<td>Images</td>
					<td>Categories</td>
					<td>Users</td>
					<td>Edit</td>
					<td>Delete</td>
				</tr>

				@foreach($posts as $post)
					<tr>
						<td>{{$post->title}}</td>
						<td>{{Str::limit($post->description,100)}}</td>
						<td>{{Str::limit($post->content,200)}}</td>
						<td><img src="{{$post->img}}" style="width:80px;height:80px" class="img-thumbnail"></td>
						<td>{{$post->categories->title}}</td>
						<td>{{$post->users->username}}</td>
						<td><a href="{{URL::route('edit_get',array($post->id))}}"><img src="{{URL::to('/')}}/public/backend/images/edit.png" ></a></td>
						<td><a href="{{URL::route('delete_get',array($post->id))}}" onclick='return confirm_delete("do you want to delete this categorie ?")'><img src="{{URL::to('/')}}/public/backend/images/delete.png" ></a></td>
					</tr>
				@endforeach

				
		</table>
	@if ($search != "")
		<a href="{{URL::route('listPost_get')}}" class="btn btn-success">Trở lại danh sách bài viết</a>
	@endif


	{{$posts->appends(array('search' => $search))->links()}}
	@else
		<table class="table table-bordered table-striped table-hover">
			<tr class="info">
				<td>Title</td>
				<td>Description</td>
				<td>Content</td>
				<td>Images</td>
				<td>Categories</td>
				<td>Users</td>
				<td>Edit</td>
				<td>Delete</td>
			</tr>

			<tr>
				<td colspan="8" align="center"><p class="alert alert-danger">Không tìm thấy bản ghi nào	</p></td>
				
			</tr>
			
		</table>
		
	@endif
@endsection
@section("data_code")
	<script language="javascript">
		function confirm_delete(err){
			if(!window.confirm(err)){
				return false;
			}
		}
	</script>
@endsection